//
//  LGHelpQuestionController.m
//  RedSunDigitalDoctor
//
//  Created by 1234 on 2022/9/28.
//

#import "LGHelpQuestionController.h"
#import "LGHelpDetailArticleController.h"
#import "LGHelpDetailVideoController.h"
@interface LGHelpQuestionController ()<UITableViewDelegate,UITableViewDataSource>

/**   */
@property (nonatomic , strong)UITableView *tableView;
/**   */
@property (nonatomic , strong)NSArray *dataArray;
/**   */
@property (nonatomic , assign)NSInteger page;

@end

@implementation LGHelpQuestionController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.page = 1;
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
    [self emptyViewWithSuperView:self.view frame:self.view.bounds];
    self.emptyView.backgroundColor = [UIColor whiteColor];
    [self requestData];
}

-(void)requestData{
    [RequestUtil withPOST:@"/doctor/help/helplists" parameters:@{@"category_id":self.catogryId,@"pageNo":@"1",@"pageSize":@"1000"} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if(code == 200){
            self.dataArray = returnData[@"data"];
            [self.tableView reloadData];
        }
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无数据" offset:0];
        }
    } error:^(NSError *error) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:@"emptyView2" content:LGErrorMessage offset:0];
        }
    }];
}

-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    self.tableView.frame = self.view.bounds;
    self.emptyView.frame = self.view.bounds;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.frame = CGRectMake(viewPix(25), 0, Screen_W-viewPix(60), viewPix(42));
    cell.textLabel.textColor = [UIColor colorWithString:@"#333333"];
    cell.textLabel.font = LGFont(16);
    cell.textLabel.text = self.dataArray[indexPath.row][@"title"];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *tempDic = self.dataArray[indexPath.row];
    
    NSString *contentType = LGNSString(tempDic[@"content_type"]);
    if([contentType isEqualToString:@"1"]){
        //文章
        LGHelpDetailArticleController *controller = [[LGHelpDetailArticleController alloc]init];
        controller.helpId = LGNSString(tempDic[@"help_id"]);
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([contentType isEqualToString:@"3"]){
        //视频
        LGHelpDetailVideoController *controller = [[LGHelpDetailVideoController alloc]init];
        controller.helpId = LGNSString(tempDic[@"help_id"]);
        [self.navigationController pushViewController:controller animated:YES];
    }
}

-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H) style:UITableViewStylePlain];
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.rowHeight = viewPix(42);
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(5))];
    }
    return _tableView;
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
